package com.bil.socket.proxy;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author litong
 * 仅仅接受客户客户端的数据,发送到服务端
 */
@Slf4j
public class SendThread extends Thread {
  private Socket clientSocket;
  private Socket remoteServetSocket;

  public SendThread(Socket clientSocket, Socket remoteServetSocket) {
    this.clientSocket = clientSocket;
    this.remoteServetSocket = remoteServetSocket;
  }

  @Override
  public void run() {
    try {
      InputStream in = clientSocket.getInputStream();
      OutputStream out = remoteServetSocket.getOutputStream();
      byte[] buf = new byte[1024 * 1024];
      int len = 0;
      int increment = 1;
      while ((len = in.read(buf)) != -1) {
        out.write(buf, 0, len);
        out.flush();
        log.info("第{}次请求,长度:{},请求数据:\r\n{}", increment++, len,new String(buf,0,len));
      }
      log.info("接收请求完成:{}", clientSocket);
    } catch (Exception e) {

    }
  }
}